#pragma once

#include "export.h"
#include "Vec.h"
#include <osg/vec3>
#include <osg/quat>
#include <string>
#include <sstream>

const double ToRad = osg::PI/180;
const double ToDeg = 180/osg::PI;

//----------------------------------------------------------------------
class DENG_EXPORT Quat 
//----------------------------------------------------------------------
{
public:
  Quat()                         {a=x=y=z=0; };
  Quat(double angle, Vec axis )  {a=angle; x=axis.x; y=axis.y; z=axis.z;};
  Quat(double angle, double vx,double vy,double vz ) {a=angle; x=vx; y=vy; z=vz;};
  
  std::string Repr() {std::ostringstream os; os << "(" << a <<") (" << x <<", " << y <<", " << z <<")"; return os.str();};

  Quat Mul(double m) {return Quat(a*m, x*m, y*m, z*m);}; 
  Quat Mul(Quat q) {return Quat(a*q.a, x*q.x, y*q.y, z*q.z);}; 
  Quat Sum(Quat q) {return Quat(a+q.a, x+q.x, y+q.y, z+q.z);}; 
  
  double a,x,y,z;

#ifndef SWIG
  void operator =(Quat q)       {a=q.a; x=q.x; y=q.y; z=q.z;};
  Quat(osg::Quat *q)            {q->getRotate(a, x, y, z ); a*=ToDeg; };
  Quat(osg::Quat  q)            { q.getRotate(a, x, y, z ); a*=ToDeg; };
  void operator =(osg::Quat *q) {q->getRotate(a, x, y, z ); a*=ToDeg; };
  void operator =(osg::Quat  q) { q.getRotate(a, x, y, z ); a*=ToDeg; };

  osg::Quat Get() { return osg::Quat( a*ToRad, osg::Vec3d(x,y,z)); };
#endif
protected:

  
  
  /*
public:
  Quat()                         {_angle=0; _axis=Vec(1,0,0); };
  Quat(double angle, Vec axis )  {_angle=angle; _axis=axis;};
  Quat(double angle, double x,double y,double z )  {_angle=angle; _axis=Vec(x,y,z);};
  
  double _angle;
  Vec    _axis;

#ifndef SWIG
  void operator =(Quat q)       {_angle=q._angle; _axis=q._axis;};
  Quat(osg::Quat *q)            {double x,y,z; q->getRotate(_angle, x, y, z ); _angle*=ToDeg; _axis=Vec(x,y,z); };
  Quat(osg::Quat  q)            {double x,y,z;  q.getRotate(_angle, x, y, z ); _angle*=ToDeg; _axis=Vec(x,y,z); };
  void operator =(osg::Quat *q) {double x,y,z; q->getRotate(_angle, x, y, z ); _angle*=ToDeg; _axis=Vec(x,y,z); };
  void operator =(osg::Quat  q) {double x,y,z;  q.getRotate(_angle, x, y, z ); _angle*=ToDeg; _axis=Vec(x,y,z); };

  osg::Quat Get() { return osg::Quat(_angle *ToRad, _axis.Get() ); };
#endif
protected:
*/
};
